home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / VCal / MonthOverview.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.0 KB  |  205 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include "MonthOverview.h"
  19. #include "OverviewDay.h"
  20. #include "VCal.h"
  21. #include "Preferences.h"
  22. #include <Vk/VkMenuBar.h>
  23. #include <Vk/VkMenuItem.h>
  24. #include <Vk/VkHelpPane.h>
  25.  
  26. #include <Sgm/Grid.h>
  27. #include <Xm/Form.h>
  28. #include <Xm/LabelG.h>
  29. #include <Xm/ToggleBG.h>
  30.  
  31. static int count;
  32. static Arg args[10];
  33.  
  34. /**********************************************************************/
  35.  
  36. MonthOverview::MonthOverview(VCal *o, const char *docName)
  37. : VkWindow(docName)
  38. {
  39.   owner = o;
  40.  
  41.   grid = NULL;
  42.   month = year = 0;
  43.   restricted = thePreferences->restricted();
  44. }
  45.  
  46. MonthOverview::~MonthOverview()
  47. {
  48.   int each;
  49.  
  50.   if (grid) {
  51.     for (each=0; each<NUM_SPOTS; each++) {
  52.       delete days[each];
  53.     }
  54.   }
  55. }
  56.  
  57. const char *
  58. MonthOverview::className()
  59. {
  60.   return "MonthOverview";
  61. }
  62.  
  63. /**********************************************************************/
  64.  
  65. void
  66. MonthOverview::selectMonth(int m, int y)
  67. {
  68.   int each, weekday, max;
  69.   int nowDay, nowMonth, nowYear;
  70.   Boolean today;
  71.   char str[256];
  72.   XmString xs;
  73.  
  74.   month = m;
  75.   year = y;
  76.   owner->getToday(&nowDay, &nowMonth, &nowYear);
  77.   weekday = computeWeekday(1, month, year);
  78.   max = NumberOfDays(month, year);
  79.   if (grid) {
  80.     formatDate(month, year, str);
  81.     xs = XmStringCreateSimple(str);
  82.     count = 0;
  83.     XtSetArg(args[count], XmNlabelString, xs);  count++;
  84.     XtSetValues(monthLabel, args, count);
  85.     XmStringFree(xs);
  86.  
  87.     for (each=0; each<NUM_SPOTS; each++) {
  88.       if (each < weekday-1 ||
  89.       each-weekday+2 > max) {
  90.     days[each]->setDate(0, 0, 0);
  91.       } else {
  92.     today = (month == nowMonth && year == nowYear &&
  93.          each-weekday+2 == nowDay);
  94.     if (restricted) {
  95.       days[each]->setDate(each-weekday+2, m, y, today,
  96.                   thePreferences->restrictStart()*MINS_IN_HOUR,
  97.                   thePreferences->restrictStop()*MINS_IN_HOUR);
  98.     } else {
  99.       days[each]->setDate(each-weekday+2, m, y, today);
  100.     }
  101.       }
  102.     }
  103.   }
  104. }
  105.  
  106. /**********************************************************************/
  107.  
  108. Widget
  109. MonthOverview::setUpInterface(Widget parent)
  110. {
  111.   int each;
  112.  
  113.   fileMenu();
  114.   if (menu()->helpPane()) {
  115.     menu()->helpPane()->setItemSensitivities(False, True, False, False,
  116.                          False);
  117.   }
  118.  
  119.   count = 0;
  120.   form = XmCreateForm(parent, "form", args, count);
  121.  
  122.   count = 0;
  123.   XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM);  count++;
  124.   XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM);  count++;
  125.   XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM);  count++;
  126.   monthLabel = XmCreateLabelGadget(form, "monthLabel", args, count);
  127.   XtManageChild(monthLabel);
  128.  
  129.   count = 0;
  130.   XtSetArg(args[count], XmNnumColumns, 7);  count++;
  131.   XtSetArg(args[count], XmNnumRows, 6);  count++;
  132.   XtSetArg(args[count], XmNtopAttachment, XmATTACH_WIDGET);  count++;
  133.   XtSetArg(args[count], XmNtopWidget, monthLabel);  count++;
  134.   XtSetArg(args[count], XmNbottomAttachment, XmATTACH_FORM);  count++;
  135.   XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM);  count++;
  136.   XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM);  count++;
  137.   grid = SgCreateGrid(form, "grid", args, count);
  138.   XtManageChild(grid);
  139.  
  140.   for (each=0; each<NUM_SPOTS; each++) {
  141.     days[each] = new OverviewDay("overviewDay", grid, owner);
  142.     days[each]->show();
  143.   }
  144.   updateDisplay();
  145.  
  146.   XtManageChild(form);
  147.   return form;
  148. }
  149.  
  150. void
  151. MonthOverview::handleWmDeleteMessage()
  152. {
  153.   doQuit();
  154. }
  155.  
  156. void
  157. MonthOverview::fileMenu()
  158. {
  159.   VkSubMenu* menu = addMenuPane("monthOverviewFileMenu");
  160.   VkMenuToggle *item;
  161.  
  162.   item = menu->addToggle("restrictedToggleMenuItem",
  163.              MonthOverview::restricted_menu,
  164.              (XtPointer) this);
  165.   item->setVisualState(thePreferences->restricted());
  166.   menu->addSeparator();
  167.   menu->addAction("monthOverviewQuitMenuItem",
  168.           MonthOverview::quit_menu,
  169.           (XtPointer) this);
  170. }
  171.  
  172. void
  173. MonthOverview::doQuit()
  174. {
  175.   hide();
  176. }
  177.  
  178. void
  179. MonthOverview::restrictedChanged(Boolean r)
  180. {
  181.   if (restricted != r) {
  182.     restricted = r;
  183.     updateDisplay();
  184.   }  
  185. }
  186.  
  187. /************************************************************/
  188.  
  189. void
  190. MonthOverview::quit_menu(Widget, XtPointer client_data, XtPointer)
  191. {
  192.   MonthOverview *obj = (MonthOverview *) client_data;
  193.  
  194.   obj->doQuit();
  195. }
  196.  
  197. void
  198. MonthOverview::restricted_menu(Widget w, XtPointer client_data, XtPointer)
  199. {
  200.   MonthOverview *obj = (MonthOverview *) client_data;
  201.  
  202.   obj->restrictedChanged(XmToggleButtonGadgetGetState(w));
  203. }
  204.  
  205.